from socket import *
from random import randint
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('0.0.0.0', serverPort))
serverSocket.listen(2)  # 控制最多可以同时监听的数量
print('The server is ready to receive')
while True:
    connectionSocket, addr = serverSocket.accept()
    sentence = connectionSocket.recv(1024).decode()
    n = int(sentence)
    res = randint(1, 3) if n % 4 == 0 else n % 4
    print('取了{}枚，还剩{}枚'.format(res, n-res))
    connectionSocket.send(str(res).encode())
